package com.itheima.service.impl.pms;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.core.PageInfo;
import com.itheima.mapper.pms.PmsProductAttributeCategoryMapper;
import com.itheima.pojo.pms.PmsProductAttributeCategory;
import com.itheima.pojo.pms.vo.ProductAttributeCategoryListWithAttrVo;
import com.itheima.service.pms.PmsProductAttributeCategoryService;
import com.itheima.service.pms.PmsProductAttributeService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class PmsProductAttributeCategoryServiceImpl extends ServiceImpl<PmsProductAttributeCategoryMapper, PmsProductAttributeCategory>implements PmsProductAttributeCategoryService {

    @Autowired
    private PmsProductAttributeCategoryMapper pmsProductAttributeCategoryMapper;

    @Override
    public PageInfo listBrand(Integer pageNum, Integer pageSize) {

        Page<PmsProductAttributeCategory> page=new Page<>(pageNum,pageSize);
        LambdaQueryWrapper<PmsProductAttributeCategory> wrapper = new LambdaQueryWrapper<>();
        Page<PmsProductAttributeCategory> pmsBrandPage = this.page(page, wrapper);
        int total = (int)pmsBrandPage.getTotal();
        int current = (int) pmsBrandPage.getCurrent();

        //封装分页数据
        PageInfo pageInfo = new PageInfo();
        pageInfo.setPageNum(pageNum);
        pageInfo.setPageSize(pageSize);
        pageInfo.setTotal(total);
        pageInfo.setTotalPage(current);
        pageInfo.setList(pmsBrandPage.getRecords());
        return pageInfo;
    }

    @Override
    public List<ProductAttributeCategoryListWithAttrVo> getListWithAttr() {
       return pmsProductAttributeCategoryMapper.getListWithAttr();
    }
}
